#!/bin/sh
filepath=$(cd "$(dirname "$0")"; pwd)
. rt.comm
rt_init
config_cont=`rtinfo`
if [ "$config_cont" == "" ]; then 
    rt_noconf
    exit 0  
fi
if [ -z "$1" ];then
    echo "Please type command. "
    exit 0
fi
dst_ip=`echo "$config_cont"|awk  -F= '{if($1~/dst_ip/)print $2}'`
dst_port=`echo "$config_cont"|awk  -F= '{if($1~/dst_port/)print $2}'`
dst_dir=`echo "$config_cont"|awk  -F= '{if($1~/dst_dir/)print $2}'`
dst_user=`echo "$config_cont"|awk  -F= '{if($1~/dst_user/)print $2}'`
dst_pwd=`echo "$config_cont"|awk  -F= '{if($1~/dst_pwd/)print $2}'`
jump_ip=`echo "$config_cont"|awk  -F= '{if($1~/jump_ip/)print $2}'`
jump_port=`echo "$config_cont"|awk  -F= '{if($1~/jump_port/)print $2}'`
jump_tmpdir=`echo "$config_cont"|awk  -F= '{if($1~/jump_tmpdir/)print $2}'`
jump_user=`echo "$config_cont"|awk  -F= '{if($1~/jump_user/)print $2}'`
jump_pwd=`echo "$config_cont"|awk  -F= '{if($1~/jump_pwd/)print $2}'`



echo "expect $filepath/rtrun.expect \"$jump_ip\" \"$jump_port\" \"$jump_user\" \"$dst_ip\" \"$dst_port\" \"$dst_dir\" \"$dst_user\"  \"$*\""
#echo $dst_dir
DIR_P=`echo $dst_dir|sed 's/.*\/home\/[^\/]*\///g'|sed 's/.*\/home\/[^\/]*//g'|sed 's/\//\\\\\//g'`
#echo $DIR_P
#expect $filepath/rtrun.expect "$jump_ip" "$jump_port" "$jump_user" "$dst_ip" "$dst_port" "$dst_dir" "$dst_user" "$dst_pwd "$*" | grep -v  "cd $dst_dir"|grep -v rtrun.expect|grep -A5000  $dst_user.*$dst_dir
expect $filepath/rtrun.expect "$jump_ip" "$jump_port" "$jump_user" "$jump_pwd" "$dst_ip" "$dst_port" "$dst_dir" "$dst_user" "$dst_pwd" "$*" | grep -v  "$dst_user.*cd $dst_dir"| awk "/$dst_user.*[>\$\#]/,/$dst_user.*[>\$\#].*exit/"
#expect $filepath/rtrun.expect $jump_ip $jump_port $jump_user $jump_pwd $dst_ip $dst_port $dst_dir $dst_user $dst_pwd "$*" 
